home *** CD-ROM | disk | FTP | other *** search
- Path: news.sprintlink.net!datalytics!usenet
- From: Rob Stewart <stew@datalytics.com>
- Newsgroups: comp.lang.c++
- Subject: Re: Visual C++ help needed!!!!(please)
- Date: Tue, 02 Apr 1996 10:29:04 -0500
- Organization: Datalytics, Inc
- Message-ID: <316147C0.3E39@datalytics.com>
- References: <4jn1cn$7vo@crash.microserve.net> <4jnb8f$18u8@mule2.mindspring.com> <4jph92$fq9@bilbo.nask.org.pl>
- NNTP-Posting-Host: 204.62.224.71
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (WinNT; I)
-
- Grzegorz (FLS) wrote:
- >
- > rudd@mindspring.com (Justin Rudd) wrote:
- >
- > >ada105@psu.edu (Alexander Achey) wrote:
- >
- > >> I'm attempting to write a Visual C++ program in which I am making it
- > >>come up with schedules of college courses. I use a modal dialog box
- > >>to get some information from the user and then I need to have it put
- > >>this data somewhere I can use it after the box is closed. I tried
- > >>putting the variables under the public part of the document class, but
- > >>I can't seem to use the GetDocument() function from the dialog box.
- > >>Is there any other way to get access to the document's member
- > >>functions or is there a better way to do this? i tried declaring this
- > >>as a global variable, but I really don't want to do that. Besides, I
- > >>keep getign redinifition errors when I do that. I'd really
- > >>apprecitate it if anyone could give me any kind of help.
- >
- > >In your dialog class have a member function that accepts a pointer to
- > >a CDocument.
- >
- > >void CMyDialog::SetDocPtr(CMyDoc* pDoc)
- > >{
- > > m_pDoc = pDoc;
- > >}
- >
- > I do not think, that declaring <SetDocPtr()> method is a good solution
- > (however it is not bad anyway ;)).
- > The solution, is to use local (public) members in CMyDialog dialog.
- > For example
- >
- > class CMyDialog : public CDialog
- > {
- > ....
- > public: // input/outpu members
- > int m_int_var ;
- > CString m_string_var ;
- > // ... etc. Sorry for members names.
- > }
- >
- > When you want to use CMyDialog, you can do:
- >
- > CMyDoc::OnEditMyDialog()
- > {
- > CMyDialog dlg ;
- >
- > if ( dlg.DoModal() == IDOK )
- > {
- > // do something with dlg.m_int_var
- > // do something with dlg.m_string_var
- > // for example:
- > m_doc_int_var = dlg.m_int_var ;
- > m_doc_string_var = dlg.m_string_var ;
- > }
- > }
- > This will work, and it is close to what you want, but it
- perpetuates Microsoft's poor C++ programming. The problem is
- the use of public dms. This is never a good idea, unless you
- declare a struct and make it obvious that you're not
- encapsulating data.
-
- The better approach is to capture the desired data in another
- class (or struct) and ask the dialog class to populate it. That
- way, you have a standard collection of the data between the
- dialog and the document classes. The dialog is free to store
- the information anyway it sees fit, including in an object of
- that class (or struct).
-
- The idea is to call a member function of the dialog object and
- have it return an object (struct) of that new type, or pass one
- into the mf by reference for it to populate. The dialog's
- representation is completely encapsulated (unless you use MFC's
- DDX functionality), and can change without affecting the code
- using it.
-
- Your document class can now manage an object (struct) of this
- new type or, if desireable, use it to populate other dms or
- objects.
-
- --
- Robert Stewart | My opinions are usually my own.
- Datalytics, Inc. | stew@datalytics.com
-